package vn.bang.xiangqi.server;

import java.io.IOException;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Scanner;

import vn.bang.xiangqi.server.log.Log;

public class ServerSide {
	
	static private final String NAME_SERVER = "localhost";
	static public final InetAddress SERVER_IP_ADDRESS = getServerIpAddress(NAME_SERVER);
	
	public static void main(String[] args) throws SocketException, IOException {
		ServerManager serverManager = new ServerManager();
		serverManager.startup();
		waitForUserStop();
		serverManager.shutdown();
	}
	
	static private void waitForUserStop() {
		Scanner reader = new Scanner(System.in);
		System.out.println("Enter the any key to stop");
		reader.next();
		reader.close();
	}
	
	static private InetAddress getServerIpAddress(String nameServer) {
		InetAddress ipAddress = null;
		try {
			ipAddress = InetAddress.getByName(nameServer);
		} catch (UnknownHostException unknownHostException) {
			Log.info("No IP address for the host could be found, or if a scope_id was specified for a global IPv6 address.", unknownHostException);
		}
		return ipAddress;
	}
	
}
